home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / os-prober < prev    next >
Encoding:
Text File  |  2007-03-14  |  2.7 KB  |  113 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. . /usr/share/os-prober/common.sh
  5.  
  6. partitions () {
  7.     if [ -d /dev/discs ]; then
  8.         find /dev/discs/ -follow -type b | grep /part
  9.     elif [ -d /sys/block ]; then
  10.         for part in /sys/block/*/*[0-9]; do
  11.             if [ -f "$part/start" ]; then
  12.                 name="$(echo "${part##*/}" | sed 's,[!.],/,g')"
  13.                 if [ -e "/dev/$name" ]; then
  14.                     echo "/dev/$name"
  15.                 fi
  16.             fi
  17.         done
  18.     else
  19.         echo "Cannot find list of partitions!" >&2
  20.         exit 1
  21.     fi
  22.  
  23.     # Also detect OSes on LVM volumes (assumes LVM is active)
  24.     if type lvs >/dev/null 2>&1; then
  25.         echo "$(lvs --noheadings --separator : -o vg_name,lv_name |
  26.             sed "s|-|--|g;s|^[[:space:]]*\(.*\):\(.*\)$|/dev/mapper/\1-\2|")"
  27.     fi
  28. }
  29.  
  30. parse_proc_mounts () {
  31.     while read line; do
  32.         set -- $line
  33.         echo "$(mapdevfs $1) $2 $3"
  34.     done
  35. }
  36.  
  37. parse_proc_mdstat () {
  38.     while read line; do
  39.         for word in $line; do
  40.             dev="${word%%[*}"
  41.             # TODO: factor this out to something in di-utils if
  42.             # it's needed elsewhere
  43.             if [ -d /sys/block ] && type udevinfo >/dev/null 2>&1; then
  44.                 if ! udevinfo -q path -n "/dev/$dev" 2>/dev/null | \
  45.                      grep -q '/.*/.*/'; then
  46.                     continue
  47.                 fi
  48.             elif ! echo "$dev" | grep -q "/part"; then
  49.                 continue
  50.             fi
  51.             raidpart="/dev/$dev"
  52.             echo "$(mapdevfs $raidpart)"
  53.         done
  54.     done
  55. }
  56.  
  57. # Needed for idempotency
  58. rm -f /var/lib/os-prober/labels
  59.  
  60. for prog in /usr/lib/os-probes/init/*; do
  61.     if [ -x $prog ] && [ -f $prog ]; then
  62.         $prog || true
  63.     fi
  64. done
  65.  
  66. # Partman mounts partitions on /dev/ide/ and /dev/scsi, not /dev/discs
  67. # Therefore we use mapdevfs to match partitions with mount points
  68. # and partitions used in RAID
  69. grep "^/dev/" /proc/mounts | parse_proc_mounts >/tmp/mounted-map || true
  70. : >/tmp/raided-map
  71. if [ -f /proc/mdstat ] ; then
  72.     grep "^md" /proc/mdstat | parse_proc_mdstat >/tmp/raided-map || true
  73. fi
  74.  
  75. for partition in $(partitions); do
  76.     if ! mapped=$(mapdevfs $partition); then
  77.         log "Device '$partition' does not exist; skipping"
  78.         continue
  79.     fi
  80.  
  81.     # Skip partitions used in software RAID arrays
  82.     if grep -q "^$mapped" /tmp/raided-map ; then
  83.         debug "$partition: part of software raid array"
  84.         continue
  85.     fi
  86.  
  87.     if ! grep -q "^$mapped " /tmp/mounted-map ; then
  88.         for test in /usr/lib/os-probes/*; do
  89.             if [ -f $test ] && [ -x $test ]; then
  90.                 debug "running $test on $partition"
  91.                 if $test $partition; then
  92.                     debug "os detected by $test"
  93.                        break
  94.                 fi
  95.             fi
  96.         done
  97.     else
  98.         mpoint=$(grep "^$mapped " /tmp/mounted-map | cut -d " " -f 2)
  99.         if [ "$mpoint" != "/target" ] && [ "$mpoint" != "/" ]; then
  100.             type=$(grep "^$mapped " /tmp/mounted-map | cut -d " " -f 3)
  101.             for test in /usr/lib/os-probes/mounted/*; do
  102.                 if [ -f $test ] && [ -x $test ]; then
  103.                     debug "running $test on mounted $partition"
  104.                     if $test $partition $mpoint $type; then
  105.                         debug "os detected by $test"
  106.                         break
  107.                     fi
  108.                 fi
  109.             done
  110.         fi
  111.     fi
  112. done
  113.